home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 22 / Amiga Format AFCD22 (Jan 1998, Issue 106).iso / -in_the_mag- / converters / graphics / netpbm / hpcdtoppm.0.6 / src / ppm.c < prev    next >
C/C++ Source or Header  |  1997-11-16  |  3KB  |  151 lines

  1. /* hpcdtoppm (Hadmut's pcdtoppm) v0.6
  2. *  Copyright (c) 1992, 1993, 1994 by Hadmut Danisch (danisch@ira.uka.de).
  3. *  Permission to use and distribute this software and its
  4. *  documentation for noncommercial use and without fee is hereby granted,
  5. *  provided that the above copyright notice appear in all copies and that
  6. *  both that copyright notice and this permission notice appear in
  7. *  supporting documentation. It is not allowed to sell this software in 
  8. *  any way. This software is not public domain.
  9. */
  10.  
  11. #include "hpcdtoppm.h"
  12.  
  13.  
  14.  
  15.  
  16. #ifdef OWN_WRITE
  17.  
  18.  
  19. static uBYTE BUF[own_BUsize];
  20. #define BUinit {BUcount=0;BUptr=BUF;}
  21.  
  22. #define BUrgb_flush        {fwrite(BUF,BUcount*3,1,fout);BUinit; }
  23. #define BUrgb_write(r,g,b) {if(BUcount>=own_BUsize/3) BUrgb_flush; *BUptr++ = r ; *BUptr++ = g ; *BUptr++ = b ; BUcount++;}
  24.  
  25. #define BUgreyflush        {fwrite(BUF,BUcount,1,fout);BUinit; }
  26. #define BUgreywrite(g)     {if(BUcount>=own_BUsize) BUgreyflush;  *BUptr++ = g ;  BUcount++;}
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34. void write_ppm(FILE *fout,dim w,dim h, 
  35.                uBYTE *rptr,sdim rzeil,sdim rpix,  
  36.                uBYTE *gptr,sdim gzeil,sdim gpix,  
  37.                uBYTE *bptr,sdim bzeil,sdim bpix) 
  38.  {register uBYTE *pr,*pg,*pb;
  39.   dim x,y;
  40.   static uBYTE *BUptr;
  41.   sINT   BUcount;
  42.  
  43.   fprintf(fout,PPM_Header,w,h);
  44.   BUinit;
  45.   for(y=0;y<h;y++)
  46.    {
  47.      pr= rptr; rptr+=rzeil;
  48.      pg= gptr; gptr+=gzeil;
  49.      pb= bptr; bptr+=bzeil;
  50.      for(x=0;x<w;x++) 
  51.       {BUrgb_write(*pr,*pg,*pb);
  52.        pr+=rpix;  pg+=gpix;  pb+=bpix;
  53.       }
  54.    }
  55.   BUrgb_flush;
  56.  
  57.  }
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64. void write_pgm(FILE *fout,dim w,dim h, uBYTE *ptr,sdim zeil,sdim pix) 
  65.  {register uBYTE *p;
  66.   dim x,y;
  67.   static uBYTE *BUptr;
  68.   sINT   BUcount;
  69.  
  70.  
  71.   fprintf(fout,PGM_Header,w,h);
  72.   BUinit;
  73.   for(y=0;y<h;y++)
  74.    {
  75.     p= ptr; ptr+=zeil;
  76.  
  77.     for(x=0;x<w;x++) 
  78.      {BUgreywrite(*p);
  79.       p+=pix;
  80.      }
  81.    }
  82.   BUgreyflush;
  83.  }
  84.  
  85.  
  86. #else
  87. #include "ppm.h"
  88.  
  89. void write_ppm(FILE *fout,dim w,dim h, 
  90.                uBYTE *rptr,sdim rzeil,sdim rpix,  
  91.                uBYTE *gptr,sdim gzeil,sdim gpix,  
  92.                uBYTE *bptr,sdim bzeil,sdim bpix) 
  93.  {register uBYTE *pr,*pg,*pb;
  94.   dim x,y;
  95.   pixel *pixrow;
  96.   register pixel* pP;
  97.  
  98.  
  99.   ppm_writeppminit(fout,w,h,(pixval) 255, 0);
  100.   pixrow = ppm_allocrow( w );
  101.   for(y=0;y<h;y++)
  102.    {
  103.     pr= rptr; rptr+=rzeil;
  104.     pg= gptr; gptr+=gzeil;
  105.     pb= bptr; bptr+=bzeil;
  106.  
  107.     for(pP= pixrow,x=0;x<w;x++)
  108.      {
  109.       PPM_ASSIGN(*pP,((sINT)*pr),((sINT)*pg),((sINT)*pb));
  110.       pP++;  pr+=rpix;  pg+=gpix;  pb+=bpix;
  111.      }
  112.     ppm_writeppmrow( fout, pixrow, w, (pixval) 255, 0 );
  113.         
  114.    }
  115.   pm_close(fout);
  116.  
  117.  }
  118.  
  119. void write_pgm(FILE *fout,dim w,dim h, uBYTE *ptr,sdim zeil,sdim pix) 
  120.  {register uBYTE *p;
  121.   dim x,y;
  122.   gray *grayrow;
  123.   register gray* pP;
  124.  
  125.  
  126.   pgm_writepgminit(fout,w,h,(pixval) 255, 0);
  127.   grayrow = pgm_allocrow( w );
  128.   for(y=0;y<h;y++)
  129.    {
  130.     p= ptr; ptr+=zeil;
  131.  
  132.     for(pP= grayrow,x=0;x<w;x++)
  133.      {
  134.       *pP= ((gray)*p);
  135.       pP++;  p+=pix;
  136.      }
  137.     pgm_writepgmrow( fout, grayrow, w, (pixval) 255, 0 );
  138.         
  139.    }
  140.   pm_close(fout);
  141.  
  142.  }
  143.  
  144.  
  145.  
  146.  
  147. #endif
  148.  
  149.  
  150.  
  151.